package com.huluspace.datajdbc.dao;

import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public class UserRoleDao {

  private final JdbcTemplate jdbcTemplate;
  public UserRoleDao(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
  }

  public List<String> findRolesByUserName(String username){
    String sql = """
        SELECT r.name
        FROM users u
        JOIN user_roles ur ON u.id = ur.user_id
        JOIN roles r ON ur.role_id = r.id
        WHERE u.username = ?
    """;
    return jdbcTemplate.queryForList(sql, String.class, username);
  }
}
